import { observable, flow } from 'mobx';
import user from '../../../common/models/user';
import { getActivities } from '../services';

class Institution {
  @observable list = [];
  @observable pending = false;

  init = flow(function*() {
    this.pending = true;
    const userInfo = yield user.getMe();
    if (!userInfo.insuranceOrgId) {
      yield user.checkApplyStatus();
    }
    try {
      const data = yield getActivities();
      if (data) {
        this.list = data;
      }
    } finally {
      this.pending = false;
    }
  });
}

export default new Institution();
